﻿
var _card_add_action = new Ext.Action({
    disabled:true,
    text: '添加',
    handler: function(){
        Ext.Msg.prompt('添加','名称',function(btn,txt){
            if(btn == 'ok'){
                var selectNode = Ext.getCmp('card_tree_panel').getSelectionModel().getSelectedNode();
                if(selectNode ==null){
                    selectNode=Ext.getCmp('card_tree_panel').root;
                }  
                Ext.Ajax.request({
                    url: '/WebHandler/cardHandler.ashx',
                    callback :function(options,success,response){
                        Ext.MessageBox.alert('信息',response.responseText);
                        Ext.getCmp('card_tree_panel').getLoader().load(selectNode);
                    },
                    params: { action: 'AddCard',name:txt,id:selectNode.id }
                });
                
                
            }
        });
    },
    iconCls: 'add'
});
var _card_remove_action = new Ext.Action({
    disabled:true,
    text: '移除',
    handler: function(){
        Ext.Msg.alert('Click', 'You did something.');
    },
    iconCls: 'remove'
});

// Panel for the west
var _west_card_panel = {
    id:'card_tree_panel',
    title: '卡片管理',
    region: 'west',
    split: true,
    width: 200,
    collapsible: true,
    //treePanle config
    useArrows: true,
    autoScroll: true,
    animate: true,
    enableDD: true,
    containerScroll: true,
    border: false,
   // rootVisible:false,
    tbar: [_card_add_action,'-',_card_remove_action],

    // auto create TreeLoader
    loader:{
        dataUrl: '/WebHandler/cardHandler.ashx',
        baseParams:{action:"GetNode"}
    },
    root: {
        nodeType: 'async',
        text:'卡片类别',
        expanded:true,
        draggable: false,
        id: 'card_node_id_0'
    }

};

var _center_card_panel = {
    title: '卡片明细', 
    region:'center'
};



//应用程序
MyDesktop.CardWindow = Ext.extend(Ext.app.Module, {
    id:'card-win',
    init : function(){
        this.launcher = {
            text: '卡片管理',
            iconCls:'icon-card',
            handler : this.createWindow,
            scope: this
        }
    },
    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('card-win');
        if(!win){
            win = desktop.createWindow({
                id: 'card-win',
                title:'卡片管理',
                width:780,
                height:480,
                iconCls: 'icon-card',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
                border:false,
                layout: 'border',
                defaults:{height: 100},
                items:[new Ext.tree.TreePanel(_west_card_panel),new Ext.Panel(_center_card_panel)]
            });
        }
        win.show();
    }
});

//将应用程序添加入桌面
MyDesktop._modules.push(new MyDesktop.CardWindow());